package com.server.runtime;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.ArrayList;

import com.server.misc.NewID;

import combat.protocol.data.PhysicalObject;
import combat.protocol.data.RemoteList;
import combat.protocol.interfaces.ProjectileInt;
import combat.protocol.interfaces.TeamInt;
import combat.protocol.interfaces.TrackInt;
import combat.protocol.interfaces.UserInt;
import combat.protocol.interfaces.VehicleInt;

public class teamImpl extends NewID.TeamID implements TeamInt, Serializable {
	private static final long serialVersionUID = 1L;
	
	private int teamID = -1;
	private String teamName = "";
	private ArrayList<UserInt> users = new ArrayList<UserInt>();
	private ArrayList<VehicleInt> vehicles = new ArrayList<VehicleInt>();
	private ArrayList<TrackInt> tracks = new ArrayList<TrackInt>();
	private ArrayList<ProjectileInt> projectiles = new ArrayList<ProjectileInt>();
	
	public teamImpl() {
	}
	
	public teamImpl(String teamName){
		this.teamID = getID();
		this.teamName = teamName;
	}
	
	public int getTeamID() {
		return teamID;
	}
	
	public void setTeamID(int teamID) {
		this.teamID = teamID;
	}

	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}

	public void addUser(UserInt user) {
		this.users.add(user);
	}

	public void removeUser(int userID) {
		this.users.remove(userID);
	}

	public void addVehicle(VehicleInt vehicle) {
		this.vehicles.add(vehicle);
	}
	
	public void removeVehicle(int vehicleID) {
		this.vehicles.remove(vehicleID);
	}

	public void removeTrack(PhysicalObject track) {
		this.tracks.remove(track);
	}

	public void removeUser(UserInt user) {
		for(int i = 0; i < users.size(); i++)
		{
			if(users.get(i).getUserID() == user.getUserID())
				users.remove(i);
		}
	}

	public ArrayList<UserInt> getUsers() {
		return this.users;
	}

	public void setUsers(ArrayList<UserInt> users) {
		this.users = users;
	}

	public ArrayList<VehicleInt> getVehicles() {
		return vehicles;
	}

	public void setVehicles(ArrayList<VehicleInt> vehicles) {
		this.vehicles = vehicles;
	}
	
	public void removeVehicle(VehicleInt vehicle) {
		this.vehicles.remove(vehicle);
	}

	public ArrayList<TrackInt> getTracks() {
		return this.tracks;
	}

	public void setTracks(ArrayList<TrackInt> tracks) {
		this.tracks = tracks;
	}

	public void addTrack(TrackInt track) {
		this.tracks.add(track);
	}

	public void removeTrack(TrackInt track) {
		this.tracks.remove(track);
	}

	public ArrayList<ProjectileInt> getProjectiles() {
		return this.projectiles;
	}

	public void setProjectiles(ArrayList<ProjectileInt> projectiles) {
		this.projectiles = projectiles;
	}

	public void addProjectile(ProjectileInt projectile) {
		this.projectiles.add(projectile);
	}

	public void removeProjectile(ProjectileInt projectile) {
		this.projectiles.remove(projectile);
	}

	@Override
	public RemoteList getUsers_Remote() {
		try {
			return new RemoteList(getUsers());
		} catch (RemoteException e) {
			System.out.println("ERROR: Update getUsers function failed");
		}
		return new RemoteList();
	}

	@Override
	public RemoteList getVehicles_Remote() {
		try {
			return new RemoteList(getVehicles());
		} catch (RemoteException e) {
			System.out.println("ERROR: Update getVehicles function failed");
		}
		return new RemoteList();
	}

	@Override
	public RemoteList getTracks_Remote() {
		try {
			return new RemoteList(getTracks());
		} catch (RemoteException e) {
			System.out.println("ERROR: Update getTracks function failed");
		}
		return new RemoteList();
	}

	@Override
	public RemoteList getProjectiles_Remote() {
		try {
			return new RemoteList(getProjectiles());
		} catch (RemoteException e) {
			System.out.println("ERROR: Update getProjectiles function failed");
		}
		return new RemoteList();
	}

}
